The Document Object Model and JavaScript > Custom JavaScript controls > Manipulating tree control content |
![]() ![]() ![]() |
Manipulating tree control content
TREECONTROLS
and TREENODES
are implemented as HTML tags, and are thus parsed by Dreamweaver and stored in the document tree. These tags can then be manipulated just like any other document node by calling DOM functions and using DOM properties already built into Dreamweaver.
Adding nodes Currently, Dreamweaver does not have a DOM function for creating new nodes within the document structure. Dreamweaver does support two properties, innerHTML
and outerHTML
, that can be used to simulate this function.
For example, to add a child node to an existing empty parent node, you would set:
parentNode.innerHTML = "<MM:TREENODE name="X" value='myNewNode'¬ expanded></MM:TREENODE>"
Deleting nodes Currently, Dreamweaver does not support a DOM function for deleting a node from the document structure. This behavior can be simulated using the innerHTML
and outerHTML
properties.
For example, to delete all child nodes of a given parent node, you would set:
parentNode.innerHTML = ""
Moving nodes Dreamweaver does not currently provide a DOM function for moving one node to another location within the document. This action can be simulated using a combination of adding and deleting nodes (using the innerHTML
and outerHTML
properties).
Modifying nodes Nodes can be directly modified using the provided Dreamweaver DOM functions.
For example, to set the "expanded" attribute of a tree node, a scripter can simply use the DOM function NODE.setAttribute('expanded','expanded')
to expand the node. All other attributes can be controlled the same way.
Traversing nodes Dreamweaver does not have built in API functions for traversing, or iterating, through nodes. This behavior can be simulated using the parentNode
, childNodes
, and hasChildNodes()
properties and methods.
For example, to retrieve the parent node of a node, you would use:
parent = node.parentNode;
Getting node data Node data can be retrieved directly from the node using the provided Dreamweaver DOM node functions and properties such as getAttribute()
, innerHTML
, and outerHTML
.
For example, to see if a node was selected, you could use:
bSelected = (node.getAttribute('selected') != null)
![]() ![]() ![]() |